/**
 * 定义月报表模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.zhuhai.reportData.monthDataManager', ['water.apps.common.report.reportFormBase',
	                                                                          'water.common.dateUtil']);
	
	module.controller('reportDataMonthManagerController',function($scope,$zhuhaiMonitorDataService,$controller,$dateUtil){

		var control = $controller("commonReportFormController",{$scope:$scope});
		$scope.stadardData={};
		var TwoTypeWaterStardard = {"065":'0.2~0.5(湖、库)',"060":'0.15~0.5',"ss_zhuodu":'',"101":'0.02~0.1',"111":'2~4',"001":'6~9',"cond":'',"do":'6~7.5',"phtem":''};
		var threeTypeWaterStardard = {"065":'0.5~1(湖、库)',"060":'0.5~1',"ss_zhuodu":'',"101":'0.1~0.2',"111":'4~6',"001":'6~9',"cond":'',"do":'5~6',"phtem":''};
		var fourTypeWaterStardard = {"065":'1~1.5(湖、库)',"060":'1~1.5',"ss_zhuodu":'',"101":'0.2~0.3',"111":'6~10',"001":'6~9',"cond":'',"do":'3~5',"phtem":''};
		$scope.stadardData.TwoTypeWaterStardard = TwoTypeWaterStardard;
		$scope.stadardData.threeTypeWaterStardard = threeTypeWaterStardard;
		$scope.stadardData.fourTypeWaterStardard = fourTypeWaterStardard;
		$scope.item = "项目";
		$scope.unit = "单位";
		$scope.Stadard_II = "地表水标准值Ⅱ类";
		$scope.Stadard_III = "地表水标准值Ⅲ类";
		$scope.Stadard_IV = "地表水标准值Ⅳ类";
		/**
		 * 年选择下拉数据
		 */
		$scope.yearlist = [{name:'2016年',value:2016},{name:'2017年',value:2017}];
		/**
		 * 月现在下拉
		 */
		$scope.monthlist = [];
		/**
		 * 选择的年份
		 */
		$scope.selectYear;
		/**
		 * 选择的月份
		 */
		$scope.selectMonth;
		
		$scope.dataAPIName = 'getMonthReport';
		$scope.dataExportAPIName = "exportMonthExcel";
		
		for(var i=1; i<=12; i++){
			$scope.monthlist.push({
				name:i+"月",
				value:i
			});
		}
		
		/**
		 * 获取查询参数
		 * forExcel 是否用于导出
		 */
		$scope.getQueryObject = function(){
			
			var dateStr = $scope.selectYear + "/" + $scope.selectMonth + "/1 00:00:00";
			var startDate = $dateUtil.createDate(dateStr);
			var endDate = $dateUtil.addMonth(startDate,1);
//			endDate =  $dateUtil.addDay(endDate,-1);
			endDate =  $dateUtil.addSecond(endDate,-1);
			
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":$dateUtil.formatDate(startDate),
					"END":$dateUtil.formatDate(endDate)
				};
			return queryObject;
		}
		
		function _init(){
			var date = new Date();
			$scope.selectYear = date.getFullYear();
			$scope.selectMonth = date.getMonth() + 1;
		}
		/**
		 * 导出excel
		 */
		$scope.onExportExcelClick = function(){
			var queryObj = $scope.getQueryObject(true);
			$zhuhaiMonitorDataService[$scope.dataExportAPIName](queryObj);
		}
		$scope.getReport = function(queryObject){
			$zhuhaiMonitorDataService[$scope.dataAPIName](queryObject).then(function(data){
				$scope.data = data;
			});
			$scope.onTBClick();
		}
		_init();
		
	});
}(window, angular));